import { defineConfig } from 'vite'
import { resolve } from 'path'
import WindiCSS from 'vite-plugin-windicss'
import uni from '@dcloudio/vite-plugin-uni'
import { vueI18n } from '@intlify/vite-plugin-vue-i18n'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { apiHost } from './src/config'
const apiHost = 'https://asa-qa.allintechinc.com'
const crmPoxyUrl = 'https://asa-qa.allintechinc.com'
export default defineConfig({
    plugins: [
        vueJsx(),
        WindiCSS(),
        uni(),
        vueI18n({
            include: resolve(__dirname, './src/locales/**'),
            defaultSFCLang: 'yml'
        })
    ],
    resolve: {
        alias: [{ find: '@', replacement: resolve(__dirname, 'src') }]
    },
    server: {
           host: '0.0.0.0', // 允许所有IP访问
          proxy: {
          
            '/solution-ppm/api/v2': {
                // target: 'http://10.10.0.201:8081',
                // target: 'http://10.20.0.204:8081',
                // target: 'http://10.10.0.174:8081',
                target: apiHost,
                // changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/solution-ppm-basic-data/api/v1': {
                // target: 'http://10.10.0.201:8081',
                // target: 'http://10.10.10.27:8084',
                // target: 'http://10.10.0.174:8081',
                target: apiHost,
                // changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/solution-ppm-work-order/api/v1': {
                // target: 'http://10.10.0.201:8081',
                // target: 'http://10.20.0.26:8082',
                // target: 'http://10.20.0.203:8083',
                target: apiHost,
                // changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/solution-crm/api/v1': {
                // target: 'http://10.20.0.232:8082',
                // target: 'http://10.20.0.204:8082',
                // target: 'http://10.10.0.119:8082',
                target: crmPoxyUrl,
                // changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/file-storage/api/v1/file/upload': {
                target: 'https://asa-qa.allintechinc.com',
                changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/config.json': {
                target: apiHost,
                changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/base/api/v1': {
                target: apiHost,
                changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/file-storage/api/v1': {
                target: apiHost,
                changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            },
            '/workflow-platform/api/v1': {
                target: apiHost,
                changeOrigin: true,
                ws: true,
                secure: false
                // rewrite: path => path.replace(/^\/dev-api/, '')
            }
        }
    },
    // server: {
    //     proxy: {
    //         '/visualization-data/api/v1': {
    //             target: apiHost,
    //             changeOrigin: true,
    //             ws: true,
    //             secure: false,
    //         }
    //     }
    // },
    build: {
        rollupOptions: {
            output: {
                manualChunks(id) {
                    if (id.includes('node_modules')) {
                        const names = id.split('node_modules/')
                        const lastPath = names[names.length - 1]
                        return '_lib_' + lastPath.split('/')[0].replace('@', '_')
                    }
                }
            }
        },
        terserOptions: {
          compress: {
            drop_debugger: true,
          }
        }
    }
})
